//
// Description: 1104. 二叉树寻路
// Created by Loading on 2021/7/29.
//

#include <bits/stdc++.h>

using namespace std;

vector<int> pathInZigZagTree(int label) {
    vector<int> res;
    while (label >= 1) {
        res.emplace_back(label);
        label >>= 1;
    }

    // 反转后为正常层序路径
    reverse(res.begin(), res.end());
    // 根据二叉树的性质，隔位修改路径值
    for (int i = (int) res.size() - 2; i > 0; i -= 2) {
        res[i] = pow(2, i) + pow(2, i + 1) - 1 - res[i];
    }

    return res;
}

int main() {
    int label = 26;
    vector<int> res = pathInZigZagTree(label);
    for (auto &x : res) {
        cout << x << " ";
    }
    cout << endl;
}